package cn.com.ebidding.order.controller;

import cn.com.ebidding.order.api.PayFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author qinchen
 * @date 2021/7/12 7:42 下午
 * 向未来的自己致敬
 * 描述：XXX
 */
@RefreshScope
@RestController
public class OrderController {

    @Value("${server.port}")
    private String port;

    /**
     * 动态刷新貌似在这老版本中存在问题，无法自动监听配置修改并刷新，@RefreshScope无效，但这不重要
     */
    @Value("${db.url:}")
    private String dbUrl;

    @Autowired
    private PayFeignService payFeignService;

    @GetMapping(value = "/home")
    public String home(@RequestParam String name) {

        System.out.println("我是订单服务！");
        System.out.println("从配置中心获取到配置：dbUrl = " + dbUrl);

        return "hi " + name + ",i am from port:" + port;
    }

    @GetMapping(value = "/home/feign")
    public String feign(@RequestParam String name) {

        System.out.println("Hi，我是订单服务测试支付服务Feign接口");

        String result = payFeignService.hi(name);

        System.out.println("调用Feign接口，返回结果：" + result);

        return "订单已支付";
    }

}
